<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<script type="text/javascript">
<!--


var idInput = "${param['idInput']}";		//保存选中ID
var nameInput = "${param['nameInput']}";	//保存选中的field
var cache = "${param['cache']}";			//父页面定义的Map型cache selectType=checkbox时，才需此参数
var fieldName = "${param['field']}";		//需要返回的字段名
var selectType = "${param['selectType']}";	//列表选择类型：checkbox或radio
var keepBy="${param['keepBy']}";			//翻页时，保存选中状态的依据 id或field
var action = "${ctx }/crm/customer!selectCustomer.action";

//初始化，将参数加至actionURL中，防止翻页丢失
//设置cache
function init(){
	var url = action;
	url+="?";
	url+="idInput="+idInput;
	url+="&nameInput="+nameInput;
	url+="&cache="+cache;
	url+="&field="+fieldName;
	url+="&selectType="+selectType;
	url+="&keepBy="+keepBy;
	$(".selectCustomerForm").attr("action",url);
	if(cache!=""){
		eval("cache="+cache);
	}
}
//选择完毕
function selectOK(){
	if(selectType=="radio") {		
		$.pdialog.closeCurrent();
		return ;
		};
	if(idInput!=""){
		$("#"+idInput).val(cache.values().toString());
	}
	$("#"+nameInput).val(cache.keys().toString());
	$.pdialog.closeCurrent();
}

//选择事件响应函数
function checkChg(){
	var chg = event.srcElement;
	var tr = $(chg).parents("tr");

	//如果是单选
	if(selectType=="radio"){
		singleSelect(tr);
		return ;
		}
	if(chg.checked){
		cache.put(field(tr),chg.value);
		}
	else{
		cache.remove(field(tr));
		}
}

//全选和反选
var toggle = false;
function selectAll(){
	if(selectType=="radio") return;
	toggle=!toggle;
	if(toggle)
	{
		$(".pageContent input[type='checkbox']").each(function(){
			this.checked = true;
			var tr = $(this).parents("tr");
			var fieldValue = field(tr);
			var id = this.value;
			cache.put(fieldValue,id);
			
			});
		
	}else
	{
		$(".pageContent input[type='checkbox']").each(function(){
			this.checked = false;
			var tr = $(this).parents("tr");
			var fieldValue = field(tr);
			cache.remove(fieldValue);
			});
	}
}
//保持已在文本框的电话号码为选中状态
function keepSelect(){
	if(selectType=="radio") return;
	$(".pageContent input[type='checkbox']").each(function(){
			var tr = $(this).parents("tr");
			var value = field(tr);
			if(cache.containsKey(value)){
				this.checked = true;
				}
		});
}

//按字段名，返回字段值
function field(tr){
	return $("."+fieldName,tr).html();
}

//单选，返回对应值后关闭
function singleSelect(tr){
	var value= field(tr);
	var id = event.srcElement.value;	
	if(idInput!=""){
		$("#"+idInput).val(id);
	}
	$("#"+nameInput).val(value);
	$.pdialog.closeCurrent();
}

$(document).ready(function(){
	typeSelectOption("CUSTOMER_LEVEL","sms_select_customer_filter_EQL_customerStar_id","name","id","${param['filter_EQL_customerStar_id']}");	
	typeSelectOption("CUSTOMER_TYPE","sms_select_customer_filter_EQL_type_id","name","id","${param['filter_EQL_type_id']}");
	init();
	keepSelect();
});
//-->
</script>
<form id="pagerForm"  class="selectCustomerForm" method="post" action="${ctx }/crm/customer!selectCustomer.action">
	<input type="hidden" name="status" value="${param.status}">
	<input type="hidden" name="keywords" value="${param.keywords}" />
	<input type="hidden" name="pageNum"  value="${page.pageNo}" />
	<input type="hidden" name="numPerPage" id="numPerPage" value="${page.pageSize}" />
	<input type="hidden" name="orderField" value="${param.orderField}" />
	<input type="hidden" name="page.pageNo" id="pageNo" value="${page.pageNo}"/>
	<input type="hidden" name="page.orderBy" id="orderBy" value="${page.orderBy}"/>
	<input type="hidden" name="page.order" id="order" value="${page.order}"/>
	<input type="hidden" name="page.pageSize" id="pageSize" value="${page.pageSize}"/>
</form>

<div class="page">
	<div class="pageHeader">
		<form class="selectCustomerForm" onsubmit="return dialogSearch(this);" action="${ctx }/crm/customer!selectCustomer.action" method="post">		
		<div class="searchBar">
			<ul class="searchContent">
				<li>
					<label>客户姓名：</label>
					<input type="text" name="filter_LIKES_linkman" value="${param['filter_LIKES_linkman']}"/>
				</li>
				<li>
					<label>手机：</label>
					<input type="text" name="filter_LIKES_mobile" value="${param['filter_LIKES_mobile']}"/>
				</li>
				<li>
					<label>类型：</label>
					<select id="sms_select_customer_filter_EQL_type_id" name="filter_EQL_type_id" >
					</select>
				</li>
				<li>
					<label>星级：</label>
					<select id="sms_select_customer_filter_EQL_customerStar_id" name="filter_EQL_customerStar_id" >
					</select>
				</li>
				
			</ul>
			<div class="subBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit"> 检 索 </button></div></div></li>
					<li><div class="buttonActive"><div class="buttonContent"><button type="button" onclick="selectOK()"> 确 定  </button></div></div></li>
				</ul>
			</div>
		</div>
		</form>
	</div>
	<div class="pageContent">
	
		<table class="table" layouth="142">
			<thead>
				<tr>
				<th onclick="selectAll();">全选</th>
				<th>姓名</th>
				<th>性别</th>
				<th>职位</th>
				<th>联系地址</th>
				<th>邮编</th>
				<th>手机</th>
				<th>固话</th>
				<th>邮箱</th>
				</tr>
			</thead>
			<tbody>
				<s:iterator value="page.result">
					<tr target="selectedId" rel="${id}">
						<td><input type="${param['selectType']}" name="ctrl" id="${id}" value="${id}" onclick="checkChg();" /></td>
						<td>
							<span class="linkman">${linkman}</span>
						</td>
						<td>
							<span class="gender"><s:if test="gender == 1">男</s:if><s:else>女</s:else></span>
						</td>
						<td>
							<span class="position">${position}</span>
						</td>
						<td>
							<span class="address">${address}</span>
						</td>
						<td>
							<span class="zip">${zip}</span>
						</td>
						<td>
							<span class="mobile">${mobile}</span>
						</td>
						<td>
							<span class="tel">${tel}</span>
						</td>
						<td>
							<span class="email">${email}</span>
						</td>
					</tr>
		</s:iterator>	
			</tbody>
		</table>
		<div class="panelBar">
			<div class="pages">
				<span>显示</span>
				<select name="numPerPage" id="showNumPerPage" onchange="dialogPageBreak({numPerPage:this.value})">
					<option value="14">14</option>
					<option value="20">20</option>
					<option value="50">50</option>
					<option value="100">100</option>
				</select>
				<span>条，共${page.totalCount}条</span>
			</div>
			
			<div class="pagination" targetType="dialog" totalCount="${page.totalCount}" numPerPage="${page.pageSize}" pageNumShown="10" currentPage="${page.pageNo}"></div>

		</div>
	</div>
</div>
